package graph;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import model.Collection;

public class FileCalculator {

	private File[] files;
	private BufferedReader bufferedReader;
	private StringTokenizer stringTokenizer;
	private HashMap<String, HashMap<Integer, Integer>> degreeSummary = new HashMap<String, HashMap<Integer, Integer>>();
	private HashMap<String, HashMap<Integer, Double>> strengthSummary = new HashMap<String, HashMap<Integer, Double>>();
	private HashMap<String, ArrayList<Integer>> K_CoreRecord = new HashMap<String, ArrayList<Integer>>();
	private HashMap<String, ArrayList<Integer>> weightCutRecord = new HashMap<String, ArrayList<Integer>>();
	private HashMap<String, HashMap<Integer, Double>> topStrengthSummary = new HashMap<String, HashMap<Integer, Double>>();

	/**
	 * 
	 * @param location
	 *            The location where graph files are kept
	 * @param percentage
	 *            the percentage of sentences to be kept
	 */
	public void calculateDegree(String location, double percentage) {
		File directory = new File(location);
		files = directory.listFiles(); // get all the files from location

		for (int i = 0; i < files.length; i++) {
			try {
				bufferedReader = new BufferedReader(new FileReader(files[i]));
				String line;

				HashMap<Integer, Integer> degreeRecord = new HashMap<Integer, Integer>();
				// in case the graph file is empty
				while ((line = bufferedReader.readLine()) != null) {

					stringTokenizer = new StringTokenizer(line, " ");
					String originNodeString = stringTokenizer.nextToken();
					String targetString = stringTokenizer.nextToken();
					String costString = stringTokenizer.nextToken();

					int originNode = Integer.parseInt(originNodeString);
					int targetNode = Integer.parseInt(targetString);
					double cost = Double.parseDouble(costString);

					// record for single direction

					if (degreeRecord.get(originNode) == null) {
						degreeRecord.put(originNode, 1);
					} else {
						int originValue = degreeRecord.get(originNode);
						degreeRecord.put(originNode, (1 + originValue));
					}
					
					if (degreeRecord.get(targetNode) == null) {
						degreeRecord.put(targetNode, 1);
					} else {
						int originValue = degreeRecord.get(targetNode);
						degreeRecord.put(targetNode, (1 + targetNode));
					}

					// bidirectional edge
					// if (degreeRecord.get(targetNode) == null) {
					// degreeRecord.put(targetNode, 1);
					// } else {
					// int originValue = degreeRecord.get(targetNode);
					// degreeRecord.put(targetNode, (1 + originValue));
					// }

				}

				if (degreeRecord.size() == 0) {
					// The document has only one edge
					System.err.println("Warning: " + files[i].getName()
							+ " has only one edge");
					HashMap<Integer, Integer> topDegreeRecord = new HashMap<Integer, Integer>();
					topDegreeRecord.put(0, 0);
					degreeSummary.put(files[i].getName(), topDegreeRecord);

				} else {

					List topFiftyKey = Collection.sortByValueDesc(degreeRecord);

					double rank = topFiftyKey.size() * percentage;
					// System.out.println("DEBUG A ::" +
					// topFiftyKey.size()+" "+rank);
					if (rank - (int) rank >= 0.5) {
						rank = (int) rank + 1;
						// System.out.println("DEBUG B ::" + rank);
					}
					HashMap<Integer, Integer> topDegreeRecord = new HashMap<Integer, Integer>();

					for (int z = 0; z < rank; z++) {
						int topNode = (Integer) topFiftyKey.get(z);
						int topDegree = degreeRecord.get(topNode);
						topDegreeRecord.put(topNode, topDegree);
					}

					// for (int topKey : topDegreeRecord.keySet()) {
					// System.out.println("Node: " + topKey + " Degree: "
					// + topDegreeRecord.get(topKey));
					// }

					degreeSummary.put(files[i].getName(), degreeRecord);
				}

			} catch (FileNotFoundException e) {

				e.printStackTrace();

			} catch (IOException e) {

				e.printStackTrace();

			}

		}

	}

	public void calculateStrenth(String location, double percentage) {
		File directory = new File(location);
		files = directory.listFiles();
		for (int i = 0; i < files.length; i++) {

			try {
				bufferedReader = new BufferedReader(new FileReader(files[i]));
				String line;

				HashMap<Integer, Double> strengthRecord = new HashMap<Integer, Double>();

				while ((line = bufferedReader.readLine()) != null) {

					stringTokenizer = new StringTokenizer(line, " ");
					String originNodeString = stringTokenizer.nextToken();

					String costString = stringTokenizer.nextToken();

					int originNode = Integer.parseInt(originNodeString);

					double cost = Double.parseDouble(costString);

					if (cost > 0) {

						if (strengthRecord.get(originNode) == null) {
							strengthRecord.put(originNode, cost);
						} else {
							double originValue = strengthRecord.get(originNode);
							strengthRecord
									.put(originNode, (cost + originValue));
						}

					}

				}

				List sortedStrengthList = Collection
						.sortByValueDesc(strengthRecord);

				int rank = (int) ((int) sortedStrengthList.size() * percentage);
				HashMap<Integer, Double> topStrengthRecord = new HashMap<Integer, Double>();

				for (int z = 0; z < rank; z++) {
					int topNode = (Integer) sortedStrengthList.get(z);
					double topDegree = strengthRecord.get(topNode);
					topStrengthRecord.put(topNode, topDegree);
				}

				topStrengthSummary.put(files[i].getName(), topStrengthRecord);

				strengthSummary.put(files[i].getName(), strengthRecord);

			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NumberFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

	public void calculateK_Core(String location, int degree, double percentage) {
		File directory = new File(location);
		files = directory.listFiles();

		double minWeight = 500;
		double maxWeight = -5;
		String fileRecordedMin = "";
		String fileRecordedMax = "";
		if (this.getDegreeSummary().isEmpty()) {
			System.out.println("Degree summary is empty");
			this.calculateDegree(location, percentage);
		}

		for (int i = 0; i < files.length; i++) {
			String fileName = files[i].getName();

			System.out.println("File name: " + fileName);

			/*
			 * HashMap<Integer, Integer> degreeForthisFile =
			 * degreeSummary.get(fileName);
			 * 
			 * for(int key: degreeForthisFile.keySet()) {
			 * System.out.println("Node: "+key+":"+degreeForthisFile.get(key));
			 * }
			 */

			try {
				bufferedReader = new BufferedReader(new FileReader(files[i]));
				String line;
				ArrayList<NodeToNode> nodeList = new ArrayList<NodeToNode>();
				ArrayList<Integer> satisfiedNodes = new ArrayList<Integer>();
				ArrayList<Integer> subGraph = new ArrayList<Integer>();

				while ((line = bufferedReader.readLine()) != null) {

					stringTokenizer = new StringTokenizer(line, " ");
					String originNodeString = stringTokenizer.nextToken();
					String destinationNodeString = stringTokenizer.nextToken();
					String costString = stringTokenizer.nextToken();

					int originNode = Integer.parseInt(originNodeString);
					int destinationNode = Integer
							.parseInt(destinationNodeString);
					double cost = Double.parseDouble(costString);

					if (cost >= 0.12) {

						NodeToNode nodeInfo = new NodeToNode(originNode,
								destinationNode, 1, cost);
						nodeList.add(nodeInfo);

						if (cost > maxWeight) {
							maxWeight = cost;
							fileRecordedMax = fileName;
						}

						if (cost < minWeight) {
							minWeight = cost;
							fileRecordedMin = fileName;
						}

					}

				}

				satisfiedNodes = this.getSatisfiedNodes(degree, fileName,
						degreeSummary); // get satisfied node for a specific
										// degree

				if (satisfiedNodes.isEmpty()) {
					System.out.println("SatisfiedNodes is empty");
					K_CoreRecord.put(fileName, subGraph);

				} else {
					/*
					 * System.out.println("SatisfiedNodes size: "+satisfiedNodes.
					 * size());
					 * 
					 * for(int f=0; f<satisfiedNodes.size();f++) {
					 * 
					 * System.out.println("Node: "+satisfiedNodes.get(f)); }
					 * 
					 * System.exit(0);
					 */

					subGraph = this
							.checkGraph(satisfiedNodes, nodeList, degree);

					if (subGraph.isEmpty()) {
						System.out.println("subgraph is empty");
						// System.exit(0);
						K_CoreRecord.put(fileName, subGraph);
					} else {
						System.out.println("subgraph size: " + subGraph.size());

						/*
						 * for(int f=0; f<subGraph.size();f++) {
						 * 
						 * System.out.println("Node: "+subGraph.get(f)); }
						 */
						// System.exit(0);

						K_CoreRecord.put(fileName, subGraph);
					}
				}

			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NumberFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

		// System.out.println("max weight: "+maxWeight+"  min weight: "+minWeight
		// +" file min recorded: "+fileRecordedMin+" file max recorded: "+fileRecordedMax);
	}

	public void calculateWeightCut(String location, int degree, double weight) {
		File directory = new File(location);
		files = directory.listFiles();

		for (int i = 0; i < files.length; i++) {
			String fileName = files[i].getName();

			System.out.println("File name: " + fileName);
			HashMap<Integer, Integer> nodeDegreeUpdated = new HashMap<Integer, Integer>();

			try {
				bufferedReader = new BufferedReader(new FileReader(files[i]));
				String line;
				ArrayList<NodeToNode> nodeList = new ArrayList<NodeToNode>();
				ArrayList<Integer> satisfiedNodes = new ArrayList<Integer>();
				ArrayList<Integer> subGraph = new ArrayList<Integer>();

				while ((line = bufferedReader.readLine()) != null) {

					stringTokenizer = new StringTokenizer(line, " ");
					String originNodeString = stringTokenizer.nextToken();
					String destinationNodeString = stringTokenizer.nextToken();
					String costString = stringTokenizer.nextToken();

					int originNode = Integer.parseInt(originNodeString);
					int destinationNode = Integer
							.parseInt(destinationNodeString);
					double cost = Double.parseDouble(costString);

					if (cost >= weight) {

						NodeToNode nodeInfo = new NodeToNode(originNode,
								destinationNode, 1, cost);
						nodeList.add(nodeInfo);

					}

				}

				// construct a hashmap which records the satisfied nodes with
				// its degree

				if (nodeList.isEmpty() || nodeList == null) {
					System.out.println("No satisfied nodes");
				} else {

					for (int h = 0; h < nodeList.size(); h++) {
						NodeToNode node = nodeList.get(h);
						int originNode = node.getOriginNode();

						if (nodeDegreeUpdated.get(originNode) != null) {

							int value = nodeDegreeUpdated.get(originNode);

							nodeDegreeUpdated.put(originNode, (value + 1));
						} else {

							nodeDegreeUpdated.put(originNode, 1);
						}
					}

					for (int key : nodeDegreeUpdated.keySet()) {
						int value = nodeDegreeUpdated.get(key);
						if (value >= degree) {
							satisfiedNodes.add(key);
						}
					}

					if (satisfiedNodes.isEmpty()) {
						weightCutRecord.put(fileName, subGraph);
					} else {
						subGraph = this.checkGraph(satisfiedNodes, nodeList,
								degree);

						if (subGraph.isEmpty()) {
							weightCutRecord.put(fileName, subGraph);
						} else {
							System.out.println("Subgraph size: "
									+ subGraph.size());
							weightCutRecord.put(fileName, subGraph);
						}

					}

				}

			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NumberFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

	// from a specific degree, get all the satisfied nodes
	public ArrayList<Integer> getSatisfiedNodes(int degree, String fileName,
			HashMap<String, HashMap<Integer, Integer>> degreeSummary) {
		HashMap<Integer, Integer> degreeInfo = degreeSummary.get(fileName);
		ArrayList<Integer> resultSet = new ArrayList<Integer>();

		for (int key : degreeInfo.keySet()) {
			int count = degreeInfo.get(key);
			if (count >= degree) {
				resultSet.add(key);
			}
		}

		return resultSet;
	}

	// check whether two given nodes are connected
	public boolean isConnected(int origin, int destination,
			ArrayList<NodeToNode> nodeList) {

		for (int i = 0; i < nodeList.size(); i++) {
			NodeToNode node = nodeList.get(i);
			if (node.getOriginNode() == origin) {
				if (node.getDesNode() == destination) {

					return true;
				}
			}

		}

		return false;

	}

	// check whether the degree of a given node in the subgraph is greater than
	// a specific degree
	public boolean checkNodeDegree(int node, int degree,
			ArrayList<Integer> subGraph, ArrayList<NodeToNode> nodeList) {
		int count = 0;
		for (int i = 0; i < subGraph.size(); i++) {
			int desNode = subGraph.get(i);
			if (this.isConnected(node, desNode, nodeList) == true) {
				count++;
			}

		}

		if (count >= degree) {

			return true;
		} else {

			return false;
		}
	}

	// recursive function, check whether the degree of each node in the subgraph
	// is greater than k
	// if not, remove that node, check again

	public ArrayList<Integer> checkGraph(ArrayList<Integer> subGraph,
			ArrayList<NodeToNode> nodeList, int degree) {
		for (int i = 0; i < subGraph.size(); i++) {
			int node = subGraph.get(i);
			if (checkNodeDegree(node, degree, subGraph, nodeList) == false) {
				subGraph.remove(i);
				checkGraph(subGraph, nodeList, degree);
			}
		}

		return subGraph;
	}

	public void writeDegreeSummaryToFile(String fileslocation,
			String desLocation, double percentage) {
		this.calculateDegree(fileslocation, percentage);
		String sep = "/";
		if (System.getProperty("os.name").contains("Windows")) {
			sep = "\\";
		}

		for (String key : degreeSummary.keySet()) {
			String fileName = desLocation + sep + key + ".degree";
			PrintWriter writer;
			try {
				writer = new PrintWriter(fileName);
				HashMap<Integer, Integer> degrees = degreeSummary.get(key);

				for (int innerKey : degrees.keySet()) {
					writer.write(innerKey + ":" + degrees.get(innerKey) + "\n");
				}

				writer.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

	public void writeStrengthSummaryToFile(String fileslocation,
			String desLocation, double percentage) {
		this.calculateStrenth(fileslocation, percentage);
		String sep = "/";
		if (System.getProperty("os.name").contains("Windows")) {
			sep = "\\";
		}

		for (String key : strengthSummary.keySet()) {
			String fileName = desLocation + sep + key + ".strength";
			PrintWriter writer;
			try {
				writer = new PrintWriter(fileName);
				HashMap<Integer, Double> degrees = strengthSummary.get(key);

				for (int innerKey : degrees.keySet()) {
					writer.write(innerKey + ":" + degrees.get(innerKey) + "\n");
				}

				writer.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

	public void writeK_CoreSummaryToFile(String fileslocation,
			String desLocation, int degree, double percentage) {

		if (this.getDegreeSummary().isEmpty()) {
			this.calculateDegree(fileslocation, percentage);

		}
		System.out.println("Start calculate K_Core");

		this.calculateK_Core(fileslocation, degree, percentage);
		System.out.println("finish calculate K_Core");
		String sep = "/";
		if (System.getProperty("os.name").contains("Windows")) {
			sep = "\\";
		}

		System.out.println("K_CoreRecord Summary: " + K_CoreRecord.size());

		for (String key : K_CoreRecord.keySet()) {
			String fileName = desLocation + sep + key + ".K_Core";
			System.out.println("File name: " + fileName);
			PrintWriter writer;
			try {
				writer = new PrintWriter(fileName);
				ArrayList<Integer> list = K_CoreRecord.get(key);

				if (list.isEmpty() == false) {
					System.out.println("write list");
					for (int i = 0; i < list.size(); i++) {
						writer.write(list.get(i) + "\n");
					}
				} else {
					writer.write("No satisfied nodes");
				}

				writer.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

	}

	public void writeWeightCutSummaryToFile(String fileslocation,
			String desLocation, int degree, double weight) {

		this.calculateWeightCut(fileslocation, degree, weight);
		String sep = "/";
		if (System.getProperty("os.name").contains("Windows")) {
			sep = "\\";
		}

		for (String key : weightCutRecord.keySet()) {
			String fileName = desLocation + sep + key + ".WeightCut";
			PrintWriter writer;
			try {
				writer = new PrintWriter(fileName);
				ArrayList<Integer> list = weightCutRecord.get(key);

				if (list.isEmpty() == false) {

					for (int i = 0; i < list.size(); i++) {
						writer.write(list.get(i) + "\n");
					}
				} else {
					writer.write("No satisfied nodes");
				}

				writer.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
	}

	public HashMap<String, HashMap<Integer, Integer>> getDegreeSummary() {
		return degreeSummary;
	}

	public void setDegreeSummary(
			HashMap<String, HashMap<Integer, Integer>> degreeSummary) {
		this.degreeSummary = degreeSummary;
	}

	public HashMap<String, HashMap<Integer, Double>> getStrengthSummary() {
		return strengthSummary;
	}

	public void setStrengthSummary(
			HashMap<String, HashMap<Integer, Double>> strengthSummary) {
		this.strengthSummary = strengthSummary;
	}

	public HashMap<String, ArrayList<Integer>> getK_CoreRecord() {
		return K_CoreRecord;
	}

	public void setK_CoreRecord(HashMap<String, ArrayList<Integer>> k_CoreRecord) {
		K_CoreRecord = k_CoreRecord;
	}

	public HashMap<String, ArrayList<Integer>> getWeightCutRecord() {
		return weightCutRecord;
	}

	public void setWeightCutRecord(
			HashMap<String, ArrayList<Integer>> weightCutRecord) {
		this.weightCutRecord = weightCutRecord;
	}

	/**
	 * 
	 * @param graphLocation
	 *            the location where graph files are kept
	 * @param desLocation
	 *            the location to which the summary files are to be saved
	 * @param percentage
	 *            percentage of the sentences to be kept
	 * @param originalTextLocation
	 *            the original blog posts
	 * @param isBidirectional
	 *            whether the graph files are bidirectional
	 */
	public void generateDegreeSummary(String graphLocation, String desLocation,
			double percentage, String originalTextLocation,
			boolean isBidirectional) {
		// if degree hasn't been calculated yet, calculate them first
		if (this.getDegreeSummary().isEmpty()) {
			System.err
					.println("***** Calculating the degree of the nodes *****");
			this.calculateDegree(graphLocation, percentage);
		}

		for (String file : degreeSummary.keySet()) {
			HashMap<Integer, Integer> doc = degreeSummary.get(file);
			if (doc.size() == 0) {
				System.err.println("Warning: File " + file
						+ " has no sentence in the summary");
			}
		}

		char sep = Collection.getSeparator();

		// once the degree scores are finalized, extract the sentences
		System.err.println("***** Extracting the summaries *****");
		for (String fileName : degreeSummary.keySet()) {
			String writeFileName = desLocation + sep + fileName
					+ "_degreeSummary.txt";
			HashMap<Integer, Integer> selectedDegree = degreeSummary
					.get(fileName);
			// Sort the sentences by index first so that they appear in order in
			// the generated summary
			List sortSelectedDegree = Collection.sortByKeysAscd(selectedDegree);

			PrintWriter writer;

			try {
				writer = new PrintWriter(writeFileName);
				for (int i = 0; i < sortSelectedDegree.size(); i++) {
					int node = (Integer) sortSelectedDegree.get(i);

					String sentence = this.retrieveSentence(fileName, node,
							originalTextLocation);
					if (sentence != null) {
						writer.write(sentence + '\n');
					}
				}
				writer.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

	}

	public void selectTopStrength(String location, String desLocation,
			double percentage, String originalTextLocation) {
		if (this.getStrengthSummary().isEmpty()) {
			this.calculateStrenth(location, percentage);
		}

		String sep = "/";
		if (System.getProperty("os.name").contains("Windows")) {
			sep = "\\";
		}

		for (String fileName : topStrengthSummary.keySet()) {
			// System.out.println("**File name: "+fileName);
			String writeFileName = desLocation + sep + fileName
					+ "_strengthSummary.txt";
			HashMap<Integer, Double> selectedStrength = topStrengthSummary
					.get(fileName);
			List sortSelectedStrength = Collection
					.sortByValueDesc(selectedStrength);
			PrintWriter writer;

			try {
				writer = new PrintWriter(writeFileName);
				for (int i = 0; i < sortSelectedStrength.size(); i++) {
					int node = (Integer) sortSelectedStrength.get(i);
					String sentence = this.retrieveSentence(fileName, node,
							originalTextLocation);
					if (sentence != null) {
						writer.write(sentence + '\n');
					}
				}
				writer.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

	}

	public void convertK_Core_Node(String location, String desLocation,
			double percentage, int degree, String originalTextLocation) {
		if (this.getDegreeSummary().isEmpty()) {
			this.calculateDegree(location, percentage);
		}

		if (this.getK_CoreRecord().isEmpty()) {
			this.calculateK_Core(location, degree, percentage);
		}

		String sep = "/";
		if (System.getProperty("os.name").contains("Windows")) {
			sep = "\\";
		}

		for (String fileName : this.getK_CoreRecord().keySet()) {
			// System.out.println("**File name: "+fileName);
			String writeFileName = desLocation + sep + fileName
					+ "_K_CoreSummary.txt";

			ArrayList<Integer> k_coreList = this.getK_CoreRecord()
					.get(fileName);

			PrintWriter writer;

			try {
				writer = new PrintWriter(writeFileName);

				for (int i = 0; i < k_coreList.size(); i++) {
					int node = k_coreList.get(i);
					String sentence = this.retrieveSentence(fileName, node,
							originalTextLocation);
					if (sentence != null) {
						writer.write(sentence + '\n');
					}
				}

				writer.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

	}

	public void convertWeightCutNode(String location, String desLocation,
			double percentage, int degree, double weight,
			String originalTextLocation) {
		if (weightCutRecord.isEmpty()) {
			this.calculateWeightCut(location, degree, weight);
		}

		String sep = "/";
		if (System.getProperty("os.name").contains("Windows")) {
			sep = "\\";
		}

		for (String fileName : weightCutRecord.keySet()) {
			// System.out.println("**File name: "+fileName);
			String writeFileName = desLocation + sep + fileName
					+ "_WeightCutSummary.txt";
			try {
				PrintWriter writer = new PrintWriter(writeFileName);

				ArrayList<Integer> weightList = weightCutRecord.get(fileName);
				if (weightList.isEmpty()) {
					writer.write("No satisfied nodes");
				} else {
					for (int i = 0; i < weightList.size(); i++) {
						int node = weightList.get(i);
						String sentence = this.retrieveSentence(fileName, node,
								originalTextLocation);
						writer.write(sentence + '\n');
					}
				}

				writer.close();

			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

	}

	/**
	 * 
	 * @param fileName
	 *            The file to extract sentences from
	 * @param node
	 *            the index of the node
	 * @param originalTextLocation
	 * @return
	 */
	public String retrieveSentence(String fileName, int node,
			String originalTextLocation) {

		File docDirectory = new File(originalTextLocation);
		File[] docfiles = docDirectory.listFiles();
		// System.out.println("File doc size: "+ docfiles.length);
		String line = "";
		for (int i = 0; i < docfiles.length; i++) {
			String sequence = docfiles[i].getName().substring(0, 27);
			String graphSequence = fileName.substring(0, 27);

			if (sequence.compareTo(graphSequence) == 0) {
				try {
					BufferedReader reader = new BufferedReader(new FileReader(
							docfiles[i]));
					for (int k = 0; k <= node; k++) {
						line = reader.readLine();
					}
					return line;
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return null;
	}

	public HashMap<String, HashMap<Integer, Double>> getTopStrengthSummary() {
		return topStrengthSummary;
	}

	public void setTopStrengthSummary(
			HashMap<String, HashMap<Integer, Double>> topStrengthSummary) {
		this.topStrengthSummary = topStrengthSummary;
	}

}
